package lgkj.meicqt20.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import lgkj.meicqt20.R;
import lgkj.meicqt20.bean.NewItemBean;


/**
 * Created by Administrator on 2017/8/16 0016.
 */

public class NewsAdapter extends BaseAdapter {

    private List<NewItemBean> mdata;
    private Context mContext;

    public void setmPositon(int mPositon) {
        this.mPositon = mPositon;
    }

    private int mPositon = 0;

    public void setData(List<NewItemBean> data) {
        if (data != null) {
            this.mdata = data;
        }
    }

    public NewsAdapter(Context context) {
        this.mContext = context;
        mdata = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return mdata.size();
    }

    @Override
    public NewItemBean getItem(int i) {
        return mdata.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        HolderView holderView = null;

        if (view == null) {
            holderView = new HolderView();
            view = LayoutInflater.from(mContext).inflate(R.layout.item_news, null);
            holderView.tv_name = (TextView) view.findViewById(R.id.tv_news_name);
            view.setTag(holderView);
        } else {
            holderView = (HolderView) view.getTag();
        }
        holderView.tv_name.setText(mdata.get(i).getNews_title());
        if (mPositon == i) {
            holderView.tv_name.setBackgroundResource(R.mipmap.news_title_check);
        } else {
            holderView.tv_name.setBackgroundResource(0);
        }

        return view;
    }

    class HolderView {
        TextView tv_name;
    }
}
